import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:work_tools/dio/http.dart';
import 'package:work_tools/page/encrypt/decrypt/decrypt_view.dart';
import 'package:work_tools/page/encrypt/encrypt/encrypt_view.dart';
import 'package:work_tools/page/mobile_list/mobiles_view.dart';
import 'package:work_tools/page/vin_list/vines_view.dart';
import 'package:work_tools/utils/utils.dart';

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  Size designSize() {
    if (Platform.isIOS || Platform.isAndroid) return const Size(750, 1624);
    return  const Size(1080, 2340);
  }

  @override
  Widget build(BuildContext context) {

    ScreenUtil.init(
      context,
      designSize: designSize(),// const Size(750, 1624),
      splitScreenMode: true,
    );

    return Scaffold(
      body: Padding(
        padding: EdgeInsets.all(40.w),
        child: Wrap(
          spacing: 40.w,
          runSpacing: 40.w,
          children: [
            // ActionWidget(title: "加密", image: "images/mishu_car.png", onTap: () => Get.to(() => EncryptPage())),
            // ActionWidget(title: "解密", image: "images/mishu_car.png", onTap: () => Get.to(() => DecryptPage())),
            ActionWidget(
              title: "vin码管理",
              image: "images/mishu_car.png",
              onTap: () {
                if (!Http.isLogin) {
                  Utils.dispatchLogin();
                  return;
                }
                Get.to(() => VinesPage());
              },
            ),
            ActionWidget(
                title: "手机号码管理",
                image: "images/mishu_car.png",
                onTap: () {
                  if (!Http.isLogin) {
                    Utils.dispatchLogin();
                    return;
                  }
                  Get.to(() => MobilesPage());
                }),
          ],
        ),
      ),
    );
  }
}

class ActionWidget extends StatelessWidget {
  final String title;
  final String image;
  final GestureTapCallback onTap;

  const ActionWidget({Key? key, required this.title, required this.image, required this.onTap}): super(key: key);

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: onTap,
      child: SizedBox(
        width: 100,
        height: 100,
        child: Column(
          children: [
            Image.asset(
              image,
              width: 80,
              height: 80,
            ),
            Text(title),
          ],
        ),
      ),
    );
  }


}
